<template>
  <div class="contaiter">
    <el-form
      ref="languageAbility"
      :model="languageAbility"
      label-position="left"
      label-width="150px"
      :rules="rules"
    >
      <el-form-item label="语种" required prop="languageName">
        <span slot="label" class="left-label">
          <span calss="cn-label">语种</span><br>
          <span class="en-label">Language</span>
        </span>

        <el-select
          v-model="languageAbility.languageName"
          placeholder="请选择语种"
        >
          <el-option
            v-for="item in ['英语', '日语', '法语', '俄语', '西班牙语']"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="掌握程度" required prop="level">
        <span slot="label" class="left-label">
          <span calss="cn-label">掌握程度</span><br>
          <span class="en-label">Level</span>
        </span>
        <el-radio
          v-for="item in ['一般', '良好', '熟练', '精通']"
          v-model="languageAbility.level"
          :label="item"
        >
          {{ item }}</el-radio>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="cancel">取消</el-button>
        <el-button
          type="primary"
          @click="submitForm('languageAbility')"
        >确定</el-button>
        <el-popconfirm
          v-if="showDel"
          title="确定删除吗？"
          class="delete-icon"
          @confirm="deleteConfirm"
        >
          <i slot="reference" class="delete-icon" />
        </el-popconfirm>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      languageAbility: {
        languageName: '', // 语言名称
        level: '' // 掌握程度
      },
      rules: {
        languageName: [
          { required: true, message: '请选择语种', trigger: 'blur' }
        ],
        level: [
          { required: true, message: '请选择掌握程度', trigger: 'change' }
        ]
      },
      index: null,
      showDel: false
    }
  },
  created() {},
  mounted() {},
  methods: {
    businessAreaChange(e) {
      console.log(e)
    },
    handleCityChange(e) {
      console.log(e)
    },
    cancel() {
      this.languageAbility = {
        languageName: '', // 语言名称
        level: '' // 掌握程度
      }
      this.showDel = false
      this.index = null
      this.$parent.$parent.closeFun('languageAbility')
      this.$nextTick(() => {
        this.$refs['languageAbility'].clearValidate()
      })
    },
    deleteConfirm() {
      this.$parent.$parent.deleteFun('languageAbility', this.index)
      this.cancel()
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const data = JSON.parse(JSON.stringify(this.languageAbility))
          this.$parent.$parent.upDate(
            'languageAbility',
            data,
            this.index
          )
          this.cancel()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    init(data, index) {
      data = JSON.parse(JSON.stringify(data))
      this.languageAbility = data
      this.index = index
      this.showDel = true
    }
  }
}
</script>

<style lang="scss" scoped>
.delete-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../../../../assets/images/delete_icon.png") no-repeat center
    center / cover;
}
</style>
